package com.prevpn.controller;

import com.prevpn.common.CommonResponse;
import com.prevpn.service.RoleRecommendationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//@RestController
//@RequestMapping("/recommend")
//public class RoleRecommendationController {
//
//    @Autowired
//    private RoleRecommendationService roleRecommendationService;
//
//    /**
//     * 根据输入的应用名称推荐角色
//     * 请求体示例：
//     * {
//     *   "directoryDomain": "local",
//     *   "appNames": ["知网", "[RDP]张三的windows桌面"]
//     * }
//     */
//    @PostMapping("/recommendByAppName")
//    public CommonResponse<List<Map<String, Object>>> recommendRolesByAppName(@RequestBody Map<String, Object> body) {
//        return roleRecommendationService.recommendRolesByAppName(body);
//    }
//}
@RestController
@RequestMapping("/api/role")
public class RoleRecommendationController {

    @Autowired
    private RoleRecommendationService roleRecommendationService;

    /**
     * 基于应用名 / 域名 / IP / IP段 推荐角色
     * 示例：
     * POST /api/role/recommend
     * {
     *     "directoryDomain": "local",
     *     "query": "192.168.1.0/24"
     * }
     */
    @PostMapping("/recommend")
    public CommonResponse<List<Map<String, Object>>> recommendRoles(@RequestBody Map<String, Object> params) {
        try {
            return roleRecommendationService.recommendRoles(params);
        } catch (Exception e) {
            e.printStackTrace();
            CommonResponse<List<Map<String, Object>>> resp = new CommonResponse<>();
            resp.setCode("500");
            resp.setMsg("推荐角色时发生异常: " + e.getMessage());
            return resp;
        }
    }
}